Have you already seen the interface of a powerful debugger such as CodeWarrior's C debugger ? It has many controls and many windows, and is really difficult to use without a really large screen. This is because C is a compiled language, so you need special tools to step in the code and to track variables.
Of course, if it was possible to execute on the fly a line written in C, this would eliminate the need for such a complicated interface.
In AppleScript, this is the case. Because AppleScript is an interpreted language, Smile could be made an interactive debugger. The plain, white, empty, text window ... is the debugger. This is because it has been given the ability to run AppleScript lines on the fly, as is documented in Scripts in text windows.
An example of debug
Suppose you are writing a routine supposed to work with file and folder names. Suppose you have written a routine intended to extract the name of a given folder, or file (in the real world, you will not want to do that, since there are simpler ways to achieve the same result).
Here is the routine (suppose it is in a script you are writing). You want to test it (in fact you could be somehow suspecting that it is not perfectly safe).
----------------------------
on NameOfAliasOrFileOrPath(theItem)
set theItem to theItem as text
set AppleScript's text item delimiters to ":"
return last item of (text items of theItem)
end NameOfAliasOrFileOrPath
----------------------------
Here is in 5 steps how to set up your debugging environment, and how to use it.
• Copy the routine to a text window
Select the whole routine. Select "Copy" ("Edit" menu) (-C). Select "New text" ("File" menu) (-N). Here is your "debugger window". Select "Paste" ("Edit" menu) (-V).
• Make an output window
Select "Make output window" ("Scripts" menu) (-space). The output window is intended to feel more comfortable, but it is optional. The debugger window is its own result window by default.
• Compile the handler
Select the whole handler (including the "on" and "end" lines) in the debugger window. Then press the Enter key (in the numeric keypad). (Alternately you can use the combination ctrl-C). The result of the compilation (a reference to the handler) is displayed in the output window.
• Provide values for the input data
We must provide a value for the variable "theItem". For a fast test, you can use the following :
----------------------------
set theItem to my path name -- the path of Smile
set theItem to my folder -- the folder of Smile
----------------------------
Copy (or type) these lines in the debugger window. Click anywhere in the first one, then press the Enter key (or the alternative ctrl-C). This will run it. The output window shows the result of the "set" operation, the file reference of Smile.
• Test the routine.
Type or copy in the debugger window :
----------------------------
NameOfAliasOrFileOrPath(theItem)
----------------------------
and press the Enter key. You can even, more simply, select this string out of the first line of the handler itself, and press the Enter key. The result of the execution of the handler will be displayed in the output window, most probably "Smile".
Now start it over. Click the second "set theItem" line. Run it (Enter key). Re-run the handler like before. Check the result. Oh oh. Here is the bug. This handler returns an empty string for folders.